<template>
  <div class="app-container">
    <template>
      <div class="hidden-md-and-up">
        <el-alert title="如若不适应手机端操作，建议使用电脑操作" type="warning" />
      </div>
    </template>
    <div class="table-container">
      <div style="padding-bottom:20px; display: flex;">
        <div style="width: 260px;">
          <label>艺术名称</label>
          <el-input v-model="search.artName" size="medium" placeholder="输入艺术名称" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>艺术来源</label>
          <el-input v-model="search.artOrigin" size="medium" placeholder="输入艺术来源" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>艺术获奖等级</label>
          <el-input v-model="search.artRewardLevel" size="medium" placeholder="请输入艺术获奖等级" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>艺术类型</label>
          <el-input v-model="search.artType" size="medium" placeholder="请输入艺术类型" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>统计分类</label>
          <el-input v-model="search.classifi" size="medium" placeholder="请输入统计分类" style="width: 160px;" />
        </div>
      </div>
      <div style="padding-bottom:20px; display: flex;">
        <div style="width: 260px;">
          <label>所属机构</label>
          <el-input v-model="search.organization" size="medium" placeholder="请输入所属机构" style="width: 160px;" />
        </div>
        <div style="width: 220px;">
          <label>专利状态</label>
          <el-select v-model="search.status" size="medium" placeholder="请选择" style="width: 160px;" @change="statusChange">
            <el-option label="全部" value="" />
            <el-option label="草稿" value="草稿" />
            <el-option label="待院级审核" value="待院级审核" />
            <el-option label="被院级退回" value="被院级退回" />
            <el-option label="待校级审核" value="待校级审核" />
            <el-option label="被校级退回" value="被校级退回" />
            <el-option label="审核通过" value="审核通过" />
          </el-select>
        </div>
        <div style="margin-left: 20px;" />
        <el-button type="success" size="medium" plain icon="el-icon-download" @click="excel_dialog = true">导出</el-button>
      </div>
      <el-table
        v-loading="paperListLoading"
        :data="paperList"
        element-loading-text="Loading"
        border
        fit
      >
        <el-table-column type="selection" align="center" width="55" />
        <!-- <el-table-column align="center" label="序号" width="55">
          <template slot-scope="scope">
            {{ scope.$index+1 }}
          </template>
        </el-table-column> -->
        <el-table-column align="center" label="艺术名称" min-width="120">
          <template slot-scope="scope">
            {{ scope.row.artName }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="艺术来源" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.artOrigin }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="艺术获奖等级" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.artRewardLevel }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="艺术类型" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.artType }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="统计分类" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.classifi }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="所属机构" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.organization }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="状态"
          min-width="70"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.status | statusFilter">{{ scope.row.status }}</el-tag>
            <el-tag v-if="scope.row.status === '被院级退回' || scope.row.status === '被校级退回'" type="warning">{{ scope.row.reason }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="分数" min-width="100">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.score }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="230">
          <template slot-scope="scope">
            <el-popover
              :ref="`popoverpass-${scope.$index}`"
              placement="top"
              width="160"
            >
              <p>确认通过吗？该操作不可撤销</p>
              <div style="text-align: right; margin: 0">
                <el-button size="mini" type="text" @click="scope._self.$refs[`popoverpass-${scope.$index}`].doClose()">取消</el-button>
                <el-button type="primary" size="mini" @click="thesis_pass(scope.$index, scope.row)">确定</el-button>
              </div>
            </el-popover>
            <el-button
              size="mini"
              @click="open_infoview_dialog(scope.row)"
            >
              查看
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="thesis_back(scope.row)"
            >
              退回
            </el-button>
            <el-button
              v-popover="`popoverpass-${scope.$index}`"
              size="mini"
              type="success"
            >
              通过
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          background
          :current-page="p1_page"
          :page-sizes="[1,2,3,10, 20, 30, 40]"
          :page-size="p1_size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="p1_total"
          @size-change="p1_sizechange"
          @current-change="p1_currentchange"
        />
        <!-- @size-change="handleSizeChange"
          @current-change="handleCurrentChange" -->
        <!-- 使用了size-change和current-change事件来处理页码大小和当前页变动时候触发的事件。 -->
      </div>
      <el-dialog title="信息总览" :visible.sync="infoview_dialog" width="75%">
        <el-collapse v-model="activeNames">
          <el-collapse-item name="1">
            <template slot="title">
              <div class="el-descriptions__title">基础信息</div>
            </template>
            <el-descriptions :column="2" size="medium" border :label-style="{width:'25%'}" :content-style="{width:'25%'}">
              <el-descriptions-item label="艺术名称">
                {{ infoview1.artName }}
              </el-descriptions-item>
              <el-descriptions-item label="艺术ID">
                {{ infoview1.artID }}
              </el-descriptions-item>
              <el-descriptions-item label="录入人">
                {{ infoview1.entered }}
              </el-descriptions-item>
              <el-descriptions-item label="艺术来源">
                {{ infoview1.artOrigin }}
              </el-descriptions-item>
              <el-descriptions-item label="艺术获奖类别">
                {{ infoview1.artRewardCate }}
              </el-descriptions-item>
              <el-descriptions-item label="艺术获奖等级">
                {{ infoview1.artRewardLevel }}
              </el-descriptions-item>
              <el-descriptions-item label="艺术类型">
                {{ infoview1.artType }}
              </el-descriptions-item>
              <el-descriptions-item label="统计分类">
                {{ infoview1.classifi }}
              </el-descriptions-item>
              <el-descriptions-item label="机构">
                {{ infoview1.organization }}
              </el-descriptions-item>
              <el-descriptions-item label="录入日期">
                {{ infoview1.enteredDate }}
              </el-descriptions-item>
              <el-descriptions-item label="一级学科">
                {{ infoview1.firstDiscipline }}
              </el-descriptions-item>
              <el-descriptions-item label="第一作者">
                {{ infoview1.leadAuthor }}
              </el-descriptions-item>
              <el-descriptions-item label="所属机构">
                {{ infoview1.organization }}
              </el-descriptions-item>
              <el-descriptions-item label="出版日期">
                {{ infoview1.publicDate }}
              </el-descriptions-item>
              <el-descriptions-item label="研究类别">
                {{ infoview1.researchCate }}
              </el-descriptions-item>
              <el-descriptions-item label="二级学科">
                {{ infoview1.secondaryDiscipline }}
              </el-descriptions-item>
              <el-descriptions-item label="审核结果">
                <el-tag :type="infoview1.status | statusFilter">{{ infoview1.status }}</el-tag>
              </el-descriptions-item>
              <el-descriptions-item label="未通过原因">
                {{ infoview1.reason }}
              </el-descriptions-item>
              <el-descriptions-item label="备注">
                {{ infoview1.notes }}
              </el-descriptions-item>
            </el-descriptions>
          </el-collapse-item>
          <el-collapse-item name="2">
            <template slot="title">
              <div class="el-descriptions__title">量化分数</div>
            </template>
            <el-dialog width="60%" title="编辑量化分数" :visible.sync="thesis_source_innerdialog" append-to-body :close-on-click-modal="false">
              <el-form ref="thesis_source_form_edit" :model="thesis_source_form" :rules="thesis_source_rules" label-position="top" label-width="160px">
                <el-form-item label="分数" prop="finalValue">
                  <el-input v-model="thesis_source_form.finalValue" />
                </el-form-item>
                <el-form-item label="算分详情" prop="Note">
                  <el-input v-model="thesis_source_form.Note" />
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="thesis_source_innerdialog = false">取 消</el-button>
                <el-button type="primary" @click="edit_thesis_source">确 定</el-button>
              </div>
            </el-dialog>
            <div style="margin-bottom: 10px;">
              <span>分数计算规则参考：</span>
              <el-link type="primary" :href="$FILE_PATH+'/file/量化细则图/艺体类成果计分规则可视化1.pdf'" target="_blank">艺体类成果计分规则可视化1</el-link>，
              <el-link type="primary" :href="$FILE_PATH+'/file/量化细则图/艺体类成果计分规则可视化2.pdf'" target="_blank">艺体类成果计分规则可视化2</el-link>
              <br>
              <span>官方文件：</span>
              <el-link type="primary" :href="$FILE_PATH+'/file/量化细则图/湖北师范大学科研工作量化管理办法（修订版）.pdf'" target="_blank">湖北师范大学科研工作量化管理办法（修订版）</el-link>
            </div>
            <el-form ref="thesis_source_form" :inline="true" :model="thesis_source_form" :rules="source_rules" label-width="80px" style="margin-left: 0;">
              <el-form-item label="分数" prop="finalValue">
                <el-input v-model="thesis_source_form.finalValue" placeholder="请直接填入分数" style="width: 200px;" />
              </el-form-item>
              <el-form-item label="算分详情" prop="Note">
                <el-input v-model="thesis_source_form.Note" placeholder="请填入算分依据" style="width: 200px;" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="addSource">提交</el-button>
              </el-form-item>
            </el-form>
            <el-table
              v-loading="sourceListLoading"
              :data="sourceList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column align="center" label="分数" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.finalValue }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="算分详情" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.Note }}
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="3">
            <template slot="title">
              <div class="el-descriptions__title">作者信息</div>
            </template>
            <el-dialog width="60%" title="编辑作者" :visible.sync="thesis_author_innerdialog" append-to-body :close-on-click-modal="false">
              <el-form ref="thesis_author_form" :model="thesis_author_form" label-position="top" label-width="160px">
                <el-form-item label="工号" prop="userAccount">
                  <el-input v-model="thesis_author_form.userAccount" disabled />
                </el-form-item>
                <el-form-item label="姓名" prop="name">
                  <el-input v-model="thesis_author_form.name" placeholder="仅支持通过工号搜索填充" disabled />
                </el-form-item>
                <el-form-item label="所属机构" prop="dept">
                  <el-input v-model="thesis_author_form.dept" placeholder="仅支持通过工号搜索填充" disabled />
                </el-form-item>
                <el-form-item label="作者类型" prop="authortype">
                  <el-select v-model="thesis_author_form.authortype" placeholder="请选择">
                    <el-option label="第一作者" value="第一作者" />
                    <el-option label="共同第一作者" value="共同第一作者" />
                    <el-option label="通讯作者" value="通讯作者" />
                    <el-option label="第二作者" value="第二作者" />
                    <el-option label="第三作者" value="第三作者" />
                    <el-option label="其他排名" value="其他排名" />
                  </el-select>
                </el-form-item>
                <el-form-item label="考核系数" prop="assessment">
                  <el-input v-model="thesis_author_form.assessment" />
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="thesis_author_innerdialog = false">取 消</el-button>
                <el-button type="primary" @click="edit_thesis_author">确 定</el-button>
              </div>
            </el-dialog>
            <el-table
              v-loading="paperAuthorListLoading"
              :data="paperAuthorList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column align="center" label="工号" min-width="100">
                <template slot-scope="scope">
                  {{ (scope.row.authortype === '校内教师' || scope.row.authortype === '校内教师' || scope.row.authortype === '校内教师' || !scope.row.authortype) && scope.row.userAccount ? scope.row.userAccount : '无' }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="姓名" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.name }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="所属院系" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.dept }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="作者类型" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.authortype }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="考核系数" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.assessment }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="个人得分" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.pscore }}
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="5">
            <template slot="title">
              <div class="el-descriptions__title">附件信息</div>
            </template>
            <el-table
              v-loading="fileListLoading"
              :data="fileList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column type="index" align="center" label="序号" width="55" />
              <el-table-column align="left" label="文件名称" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.filename }}
                </template>
              </el-table-column>
              <el-table-column align="left" label="文件大小" min-width="150">
                <template slot-scope="scope">
                  <span v-if="scope.row.filesize / 1024 / 1024 < 1">{{ (scope.row.filesize / 1024).toFixed(2) + 'KB' }}</span>
                  <span v-else>{{ (scope.row.filesize / 1024 / 1024).toFixed(2) + 'MB' }}</span>
                </template>
              </el-table-column>
              <el-table-column align="left" label="上传时间" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.filedate }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="操作" width="150">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    @click="downloadFile(scope.row)"
                  >
                    下载
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="6">
            <template slot="title">
              <div class="el-descriptions__title">审核记录</div>
            </template>
            <el-table
              v-loading="paperAuditListLoading"
              :data="paperAuditList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column type="index" align="center" label="序号" width="55" />
              <el-table-column align="center" label="审核员职位" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditerRole }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="审核员姓名" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditerName }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="项目状态变化" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.statusChange }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="审核意见" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditOpinion }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="审核时间" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditerTime }}
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
        </el-collapse>
        <div slot="footer" class="dialog-footer">
          <el-button @click="infoview_dialog = false">关 闭</el-button>
        </div>
      </el-dialog>
      <el-dialog title="导出excel" :visible.sync="excel_dialog" width="60%">
        <el-alert
          title="请选择需要导出的数据"
          type="success"
          description="选择的数据为表头，未选择的数据将不会导出"
          :closable="false"
        />
        <div style="margin: 15px;">
          <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选</el-checkbox>
          <div style="margin: 15px 0;" />
          <el-checkbox-group v-model="check_fields" @change="handleCheckedFieldsChange">
            <el-checkbox v-for="field in fields_list" :key="field" :label="field">{{ field }}</el-checkbox>
          </el-checkbox-group>
        </div>
        <!-- <el-alert
          title="请选择时间范围"
          type="success"
          description="选择导出数据的时间范围"
          :closable="false"
        /> -->
        <div slot="footer" class="dialog-footer">
          <el-button @click="excel_dialog = false">关 闭</el-button>
          <download-excel
            style="display:inline-block !important;margin-left:10px;"
            :data="EXCEL.DetailsForm"
            :fields="EXCEL.json_fields"
            :header="EXCEL.title"
            type="xls"
            name="艺体成果数据导出.xls"
            :fetch="createExportData"
            :before-generate="startDownload"
            :before-finish="finishDownload"
          >
            <!-- 上面可以自定义自己的样式，还可以引用其他组件button -->
            <el-button type="success" plain>确认导出</el-button>
          </download-excel>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { getQulification, getMyPaperList, update_thesis_source, getUserArts, thesis_pass_yuanji, thesis_back_yuanji, get_file, GetArtDTOById, get_thesis_author, thesis_author_edit, thesis_author_add } from '@/api/art'
import { get_thesis_Audit } from '@/api/audit'
import { Message, Loading } from 'element-ui'
import { mapGetters } from 'vuex'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        草稿: 'info',
        待院级审核: '',
        被院级退回: 'warning',
        待校级审核: '',
        被校级退回: 'danger',
        审核通过: 'success'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      thesis_source_form: {
        source_cascader_value: [], // 联级选择
        finalValue: 0,
        artID: '',
        artQualificationID: '',
        artType1: '',
        artType2: '',
        artType3: '',
        artType4: '',
        num: '',
        type1ID: 0,
        type2ID: 0,
        type3ID: 0,
        type4ID: 0
      },
      thesis_author_form: {
        assessment: '',
        authortype: '',
        dept: '',
        name: '',
        userAccount: '',
        artID: '',
        peopleType: '校内教师'
      },
      thesis_author_form_activeName: 'first',
      sourceListLoading: false,
      sourceList: [],
      search: {
        artName: '',
        artOrigin: '',
        artRewardLevel: '',
        artType: '',
        classifi: '',
        organization: '',
        status: ''
      },
      infoview_dialog: false,
      paperList: null,
      paperListLoading: false,
      paperAuthorList: null,
      paperAuthorListLoading: false,
      paperProjectList: null,
      paperProjectListLoading: false,
      paperAuditList: [],
      paperAuditListLoading: false,
      p1_size: 10,
      p1_total: 0,
      p1_page: 1,
      back_post: {
        id: '',
        reason: ''
      },
      infoview1: {},
      activeNames: ['1', '2', '3', '4', '5', '6'],
      excel_dialog: false,
      all_fields: {
        '所有作者': 'allAuthor',
        '作品名称': 'artName',
        '作品来源': 'artOrigin',
        '作品获奖类别': 'artRewardCate',
        '作品获奖等级': 'artRewardLevel',
        '作品类型': 'artType',
        '统计分类': 'classifi',
        '录入人': 'entered',
        '录入日期': 'enteredDate',
        '一级学科': 'firstDiscipline',
        '第一作者': 'leadAuthor',
        '备注': 'notes',
        '所属机构': 'dept',
        '出版日期': 'publicDate',
        '未通过原因': 'reason',
        '研究类别': 'researchCate',
        '二级学科': 'secondaryDiscipline',
        '审核结果': 'status',
        '量化分数': 'score'
      },
      fields_list: [
        '所有作者',
        '作品名称',
        '作品来源',
        '作品获奖类别',
        '作品获奖等级',
        '作品类型',
        '统计分类',
        '录入人',
        '录入日期',
        '一级学科',
        '第一作者',
        '备注',
        '所属机构',
        '出版日期',
        '未通过原因',
        '研究类别',
        '二级学科',
        '审核结果',
        '量化分数'
      ],
      check_fields: [],
      checkAll: false,
      isIndeterminate: false,
      EXCEL: {
        title: '测试表格',
        json_fields: null,
        DetailsForm: null
      },
      source_rules: {
        finalValue: [
          { required: true, message: '分数不能为空', trigger: 'blur' },
          {
            pattern: /^([1-9]\d*|0)(\.\d{1,2})?$/,
            message: '分数只能输入数字',
            trigger: ['blur', 'change']
          }
        ],
        Note: [
          { required: true, message: '算分详情不能为空', trigger: 'blur' }
        ]
      },
      fileList: [],
      fileListLoading: false,
      thesis_author_innerdialog: false,
      thesis_source_innerdialog: false,
      innerdialog1_title: '新增作者',
      innerdialog1_add: true,
      thesis_source_rules: {
        finalValue: [
          { required: true, message: '分数不能为空', trigger: 'blur' },
          {
            pattern: /^([1-9]\d*|0)(\.\d{1,2})?$/,
            message: '分数只能输入数字',
            trigger: ['blur', 'change']
          }
        ],
        Note: [
          { required: true, message: '算分详情不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters([
      'uid',
      'roles',
      'name',
      'dept'
    ]),
    YuanjiPaperPost() {
      return {
        pageNum: this.p1_page,
        pageSize: this.p1_size,
        ...this.search
      }
    }
  },
  watch: {
    search: {
      handler() {
        this.paperListLoading = true
        clearTimeout(this.searchTimeout)
        this.searchTimeout = setTimeout(() => {
          this.fetchPaperData()
          this.paperListLoading = false
        }, 1000)
      },
      deep: true // 启用深度监视，可监听对象内部属性变化
    }
  },
  created() {
    this.fetchPaperData()
  },
  methods: {
    fetchPaperData() {
      this.paperListLoading = true
      getUserArts(this.YuanjiPaperPost).then(response => {
        if (response.code === 200) {
          this.paperList = response.data.list
          this.p1_total = response.data.total
          this.paperListLoading = false
        }
      })
    },
    p1_sizechange(newsize) {
      this.p1_size = newsize
      this.p1_page = 1
      this.fetchPaperData()
    },
    p1_currentchange(newpage) {
      this.p1_page = newpage
      this.fetchPaperData()
    },
    filterTag(value, row) {
      return row.status === value
    },
    thesis_back(row) {
      this.$prompt('请输入退回原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^.+$/,
        inputErrorMessage: '原因不能为空'
      }).then(({ value }) => {
        this.back_post.id = row.artID
        this.back_post.reason = value
        thesis_back_yuanji(this.back_post).then(response => {
          if (response.code === 200) {
            Message.success('退回成功')
            this.fetchPaperData()
          }
        })
      }).catch(() => {
        Message.info('取消退回')
      })
    },
    thesis_pass(index, row) {
      this.$refs[`popoverpass-${index}`].doClose()
      thesis_pass_yuanji(row.artID).then(response => {
        if (response.code === 200) {
          Message.success('通过成功')
          this.fetchPaperData()
        }
      })
    },
    fetchOneData() {
      GetArtDTOById(this.infoview1.artID).then(response => {
        if (response.code === 200) {
          this.infoview1 = response.data
          // 映射字段
          this.infoview1.organization = response.data.deptName
          this.infoview1.entered = response.data.enteredName
        }
      })
    },
    fetch_thesis_author() {
      this.paperAuthorListLoading = true
      get_thesis_author(this.infoview1.artID).then(response => {
        if (response.code === 200) {
          this.paperAuthorList = response.data
          this.paperAuthorListLoading = false
        }
      })
    },
    open_infoview_dialog(row) {
      this.infoview_dialog = true
      this.infoview1.artID = row.artID
      this.fetchOneData()
      this.fetch_thesis_author()
      this.sourceListLoading = true
      getQulification(row.artID).then(response => {
        if (response.code === 200) {
          this.sourceList = response.data
          this.sourceListLoading = false
        }
      })
      this.fileListLoading = true
      get_file(row.artID).then(response => {
        if (response.code === 200) {
          this.fileList = response.data
          this.fileListLoading = false
        }
      })
      this.paperAuditListLoading = true
      get_thesis_Audit(row.artID).then(response => {
        if (response.code === 200) {
          this.paperAuditList = response.data
          this.paperAuditListLoading = false
        }
      })
    },
    downloadFile(row) {
      var a = document.createElement('a')
      var event = new MouseEvent('click')
      // 确保文件路径正确拼接，处理fileupload文件夹的路径
      let fileUrl = row.fileurl
      if (!fileUrl.startsWith('https')) {
        // 如果不是完整URL，则拼接FILE_PATH
        if (fileUrl.startsWith('/')) {
          fileUrl = this.$FILE_PATH + fileUrl
        } else {
          fileUrl = this.$FILE_PATH + '/' + fileUrl
        }
      }
      a.href = fileUrl
      a.target = '_blank'
      a.dispatchEvent(event)
    },
    // 以下为数据导出
    handleCheckAllChange(val) {
      this.check_fields = val ? this.fields_list : []
      this.isIndeterminate = false
      this.EXCEL.json_fields = JSON.parse(JSON.stringify(this.all_fields, this.check_fields))
    },
    handleCheckedFieldsChange(value) {
      const checkedCount = value.length
      this.checkAll = checkedCount === this.fields_list.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.fields_list.length
      this.EXCEL.json_fields = JSON.parse(JSON.stringify(this.all_fields, this.check_fields))
    },
    async createExportData() {
      return await getMyPaperList(this.YuanjiPaperPost).then(response => {
        if (response.code === 200) {
          if (response.data.list.length === 0) {
            Message.warning('返回数据为空，导出失败！')
            this.loadingInstance.close()
          }
          return response.data.list
        }
      })
    },
    startDownload() {
      this.excel_dialog = false
      this.loadingInstance = Loading.service({ text: '正在导出...' })
    },
    finishDownload() {
      setTimeout(() => {
        this.loadingInstance.close()
      }, 1000)
    },
    addSource() {
      this.$refs.thesis_source_form.validate(valid => {
        if (valid) {
          // 这里应该调用相应的API来提交分数
          // 由于没有具体的API，这里只是一个示例
          console.log('提交分数:', this.thesis_source_form)
          Message.success('提交成功')
        } else {
          Message.error('请检查输入内容')
        }
      })
    },
    resetForm(formName) {
      if (this.$refs[formName]) {
        this.$refs[formName].resetFields()
      }
    },
    open_thesis_author_innerdialog() {
      this.thesis_author_innerdialog = true
      this.resetForm('thesis_author_form')
    },
    open_edit_author_innerdialog(index, row) {
      this.thesis_author_innerdialog = true
      this.resetForm('thesis_author_form')
      this.thesis_author_form = JSON.parse(JSON.stringify(row))
    },
    open_add_author_innerdialog() {
      this.open_thesis_author_innerdialog()
      this.innerdialog1_title = '新增作者'
      this.innerdialog1_add = true
    },
    open_edit_source_innerdialog(index, row) {
      this.thesis_source_innerdialog = true
      this.thesis_source_form = { ...row }
    },
    edit_thesis_source() {
      this.$refs.thesis_source_form.validate((valid) => {
        if (valid) {
          update_thesis_source(this.thesis_source_form).then(response => {
            if (response.code === 200) {
              Message.success('保存成功')
              this.thesis_source_innerdialog = false
              this.fetchPaperData()
              this.infoview1.score = this.thesis_source_form.finalValue
              this.open_infoview_dialog(this.infoview1)
            }
          })
        } else {
          Message.error('请检查输入内容')
        }
      })
    },
    add_thesis_author() {
      this.$refs.thesis_author_form.validate(valid => {
        if (valid) {
          this.thesis_author_form.artID = this.infoview1.artID
          thesis_author_add(this.thesis_author_form).then(response => {
            if (response.code === 200) {
              Message.success('保存成功')
              this.thesis_author_innerdialog = false
              this.fetch_thesis_author()
              this.fetchOneData()
            }
          })
        } else {
          Message.error('请填写完整信息')
          return false
        }
      })
    },
    edit_thesis_author() {
      thesis_author_edit(this.thesis_author_form).then(response => {
        if (response.code === 200) {
          Message.success('保存成功')
          this.thesis_author_innerdialog = false
          this.fetch_thesis_author()
        }
      })
    }
  }
}
</script>

<style lang="scss">
.el-form{
  margin-left: 40px;
  .el-input,.el-select{
    width: 300px;
  }
}
@media screen and (max-width:600px) {
  .el-dialog{
    width: 100% !important;
  }
  .el-form{
    margin-left: 25px;
  }
}
</style>
